package net.vinote.sosa.rmi;

import org.springframework.beans.factory.FactoryBean;

public class RmiServerFactoryBean<T> implements FactoryBean<T> {
	private Class<T> interfaceName;
	private T interfaceImpl;
	private RmiServer rmiServer;

	public void publishService() {
		rmiServer.publishService(interfaceName.getName(), interfaceImpl);
	}

	@Override
	public T getObject() throws Exception {
		return interfaceImpl;
	}

	@Override
	public Class<T> getObjectType() {
		return interfaceName;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	/**
	 * Setter method for property <tt>interfaceName</tt>.
	 *
	 * @param interfaceName
	 *            value to be assigned to property interfaceName
	 */
	public final void setInterfaceName(Class<T> interfaceName) {
		this.interfaceName = interfaceName;
	}

	/**
	 * Setter method for property <tt>interfaceImpl</tt>.
	 *
	 * @param interfaceImpl
	 *            value to be assigned to property interfaceImpl
	 */
	public final void setInterfaceImpl(T interfaceImpl) {
		this.interfaceImpl = interfaceImpl;
	}

	/**
	 * Setter method for property <tt>rmiServer</tt>.
	 *
	 * @param rmiServer
	 *            value to be assigned to property rmiServer
	 */
	public final void setRmiServer(RmiServer rmiServer) {
		this.rmiServer = rmiServer;
	}

}
